# Contributor: Sebastian Hudak <sebastian@sebsite.pw>
# Maintainer: Sebastian Hudak <sebastian@sebsite.pw>
pkgname=cosmopolitan
pkgver=1.0
pkgrel=0
pkgdesc="Build-once run-anywhere C library"
url="https://justine.lol/cosmopolitan/"
arch="x86_64"
license="ISC"
subpackages="$pkgname-doc"
source="https://justine.lol/cosmopolitan/cosmopolitan-$pkgver.tar.gz
	no-clang-test.patch
	"
options="!fhs !check" # installs to /opt, checks fail on builders
builddir="$srcdir/cosmopolitan"

_mode=rel

build() {
	# Build doesn't work with custom *FLAGS.
	# This is due to the nature of Cosmpolitan and APE binaries and
	# probably can't be worked around.
	make CFLAGS= CXXFLAGS= CPPFLAGS= LDFLAGS= MODE="$_mode" \
		o/cosmopolitan.h \
		o/cosmopolitan.html \
		o/"$_mode"/ape \
		o/"$_mode"/cosmopolitan.a \
		o/"$_mode"/libc
}

check() {
	make CFLAGS= CXXFLAGS= CPPFLAGS= LDFLAGS= MODE="$_mode" \
		o/"$_mode"/test/libc
}

package() {
	install -Dm644 o/cosmopolitan.h \
		"$pkgdir"/opt/cosmopolitan/include/cosmopolitan.h
	install -Dm644 o/cosmopolitan.html \
		"$pkgdir"/usr/share/doc/cosmopolitan.html
	install -Dm644 o/"$_mode"/ape/* \
		-t "$pkgdir"/opt/cosmopolitan/lib/
	install -m644 o/"$_mode"/cosmopolitan.a \
		"$pkgdir"/opt/cosmopolitan/lib/cosmopolitan.a
	install -m644 o/"$_mode"/libc/crt/crt.o \
		"$pkgdir"/opt/cosmopolitan/lib/crt.o
}

sha512sums="
1fb01ad95d5d0908e608febd191545ca2ed06d37ff64715c3241528be2f36f656b68103178c925a8d0a985a9fd40f8f62e034a05ed719d682c5b1c336ff25c8d  cosmopolitan-1.0.tar.gz
b6d892a8ecc0a50a8cae49a0ba4ef9940316ee4ff9c36f247bda521c2ffb853062c56716bd8226144348760b581bc2cf5c65a06775162c362b4e966ac413409a  no-clang-test.patch
"
